package cashe;
public class ImmutableCache<K, V> implements ValueCache<K, V> {

	volatile Pair pair;

	@Override
	public V get(K key) {
		Pair pair = this.pair;
		
		if (pair == null)
			return null;
		if (key.equals(pair.key)) {
			return pair.val;
		} else {
			return null;
		}
	}

	@Override
	public void put(K key, V val) {
		pair = new Pair(key, val);
	}

	class Pair {
		K key;
		V val;

		public Pair(K key, V val) {
			this.key = key;
			this.val = val;
		}
	}
}
